﻿@{
    ViewBag.Title = "编辑剪切下料卡";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<link href="~/Content/css/common.css" rel="stylesheet" />
<link href="~/Content/css/BlankingcardAdd.css" rel="stylesheet" />
<style type="text/css">
    .tool_c {
        padding: 10px 0;
    }

    .btn-group {
        padding: 0 10px 0 0;
    }

    .frozen_fixed {
        overflow: hidden;
    }

        .frozen_fixed .frozen-bdiv {
            top: 51px !important;
        }

        .frozen_fixed .frozen-div {
            height: 4.2em !important;
        }

        .frozen_fixed .ui-jqgrid-hdiv {
            width: 1900px !important;
            background-color: transparent !important;
        }

        .frozen_fixed .ui-jqgrid-bdiv {
            width: 1900px !important;
            background-color: transparent !important;
        }

        .frozen_fixed .ui-jqgrid-btable {
            background-color: #fff !important;
        }

        .line_input input{
            height:2em!important;
        }

</style>
<script>
    $(function () {
        Index.init();
    });

    var Index = {
        dataList:null,
        init: function () {
            with (Index) {
                 

                loadDataList();
                initControl();
            }
        },
        initControl: function () {
  

            $("#butnBack").on("click", function () {
                $.goBack();
            });

            $("#butnGoSortExample").on("click", function () {
                var jsonData = {};
                
                var cols = "ProNoNum,RoughsSize,MaterialCode_S,FProductionNO,MaterialSizes_SH,MaterialSizes_SK,MaterialSizes_SC,MaterialSizes_JK,MaterialSizes_JC".split(",");

                var ids = "FYKJJ_GY,RoughsSize,MaterialCodeALL,FProductionNO,MaterialSizesAllT,MaterialSizesAllH,MaterialSizesAllW,MaterialSizes_JH,MaterialSizes_JW".split(",");

                var num = $("#gridList1").jqGrid("getGridParam", "selrow");

                var selected = {};

                !!num || $.modalAlert("请先选择数据");

                !!num && (function () {
                    
                    !!Index.dataList && (function () {
                        selected = Index.dataList.rows[num - 1];
                    })();

                    jsonData["item"] = JSON.stringify(selected);

                    for (var i = 0; i < cols.length; i++) {
                        jsonData[cols[i]] = $("#{0}".format(ids[i])).val();
                    }

                    $.post("/BOM/Blankingcard/LayoutSet", jsonData, function (res) {
                        !!res.result && (function (FProductionNO) {
                            //MatListID
                            var url = "/BOM/Blankingcard/BlankingcardLayout?FProductionNO={0}".format(FProductionNO);

                            location.href = url;
                        })(res.FProductionNO);
                    }, "json");

                   
                })();
            });

            $("#butnGoArtPic").on("click", function () {
                var jsonData = { id: "" };

                var num = $("#gridList1").jqGrid("getGridParam", "selrow");

                !!num || $.modalAlert("请先选择数据");

                !!num && (function () {
                    !!Index.dataList && (function () {
                        jsonData.id = Index.dataList.rows[num - 1]["MatListID"];
                    })();

                    var url = "/BOM/Blankingcard/BlankingcardArtPic?{0}".format($.param(jsonData));

                    $.modalOpen({
                        url: url,
                        width: "800px",
                        height: "800px",
                        close:true
                    });
                })();
            });

            $("#butnQueryDetails").on("click", function () {
                var jsonData = {}, cols = "MaterialCodeALL,MaterialSizesAllT".split(",");
                
                cols.forEach(function (item) {
                    jsonData[item] = $("#{0}".format(item)).val();
                });

                var url = "/BOM/Blankingcard/BlankingcardMaterialBoards?{0}".format($.param(jsonData));

                $.modalOpen({
                    id:"openDlgMb",
                    url: url,
                    width: "1200px",
                    height: "600px",
                    close:true,
                    callBack: function (id) {
                        var dests = "MaterialCode,MaterialSizesT".split(","), jsonData = {},i=0;

                        dests.forEach(function (item) {
                            $("#{0}".format(cols[i++])).val(parent.parent.$("#{0}".format(id)).find("iframe").contents().find("#{0}".format(item)).val());
                        });
                    }
                });
            });

            $("#btn_search1").on("click", function () {
                var $gridList1 = $("#gridList1");

                var conn1 = {
                    "ProductionNO": $("#ProductionNo2").val(),
                    "MaterialCodeAll": $("#MaterialCodeAll2").val(),
                    "MaterialSizesAll": $("#MaterialSizesAll2").val(),
                    "IsBZGY": $("#IsBZGY2").val(),
                    "IsImg": $("#IsImg2").val(),
                    "RoughsType": $("#RoughsType2").val()
                };

                $gridList1.jqGrid('setGridParam', {
                    postData: conn1,
                }).trigger('reloadGrid');
            });
        },
        loadDataList: function () {
            var conn1 = {
                "ProductionNO": $("#ProductionNo2").val(),
                "MaterialCodeAll": $("#MaterialCodeAll2").val(),
                "MaterialSizesAll": $("#MaterialSizesAll2").val(),
                "IsBZGY": $("#IsBZGY2").val(),
                "IsImg": $("#IsImg2").val(),
                "RoughsType": $("#RoughsType2").val()
            };
            var $gridList1 = $("#gridList1");///BOM/Blankingcard/GetBlankingcards
            $gridList1.dataGridForJson({
                url: "/BOM/Blankingcard/GetBlankingcardAdds",
                postData: conn1,
                height: $(window).height() - 360,
                colModel: [
                    { label: '编号', name: 'CldeID', width: 40, align: 'left', sortable: false, hidden: true },
                    { label: '材料牌号', name: 'LsNetWeight', width: 40, align: 'left', sortable: false, hidden: true },
                     { label: '材料牌号', name: 'MaterialNo', width: 40, align: 'left', sortable: false, hidden: true },
                    { label: '纤维方向', name: 'FiberDirection', width: 40, align: 'left', sortable: false, hidden: true },
                { label: '零件编号', name: 'FProductionNO', width: 40, align: 'left', sortable: false, hidden: true },
                { label: '下料方式', name: 'IsBZGY', width: 40, align: 'center', sortable: false, hidden: true },
                { label: '剪切图形', name: 'ISImg', width: 40, align: 'center', sortable: false, hidden: true },
                { label: '毛坯类别', name: 'RoughsType', width: 40, align: 'center', sortable: false, hidden: true },
                 { label: '工艺材料规格', name: 'MaterialSizes', width: 40, align: 'center', sortable: false, hidden: true },
                { label: '实际材料规格', name: 'MaterialSizes_SJBL', width: 40, align: 'center', sortable: false, hidden: true },
                 { label: '实际材料牌号', name: 'MaterialCode_SJBL', width: 40, align: 'center', sortable: false, hidden: true },
                 { label: '工艺材料牌号', name: 'MaterialCode', width: 40, align: 'center', sortable: false, hidden: true },
                { label: '零件编号', name: 'FProductionNOName', width: 160, align: 'left', sortable: false, frozen: true },
                { label: '下料<br/>方式', name: 'IsBZGYName', width: 40, align: 'center', sortable: false, frozen: true },
                { label: '剪切图形', name: 'ISImgName', width: 160, align: 'center', sortable: false, frozen: true },
                { label: '材料牌号', name: 'MaterialCode_ALL', width: 160, align: 'left', sortable: false, frozen: true },
                { label: '材料规格', name: 'MaterialSizes_ALL', width: 160, align: 'left', sortable: false, frozen: true },
                { label: '开卷<br/>尺寸', name: 'MaterialSizes_K1', width: 40, align: 'right', sortable: false },
                { label: '剪切规格', name: 'MaterialSizes_J', width: 160, align: 'right' },
                { label: '一张<br/>几块	', name: 'FYZJK	', width: 40, align: 'right', sortable: false },
                { label: '一块<br/>几张', name: 'FYKJJ', width: 40, align: 'right', sortable: false },
                { label: '工艺一张<br/>几块', name: 'FYZJK_GY', width: 80, align: 'right', sortable: false },
                { label: '工艺一块<br/>几件', name: 'FYKJJ_GY', width: 80, align: 'right', sortable: false },
                { label: '一张<br/>几件', name: 'KZLJ', width: 40, align: 'right', sortable: false },
                { label: '方<br/>向', name: 'FiberdirectionName', width: 30, align: 'center', sortable: false },
                 { label: '毛坯<br/>类别', name: 'RoughsTypeName', width: 40, align: 'center', sortable: false },
                { label: '毛坯尺寸(mm)', name: 'RoughsSize', width: 160, align: 'left'},
                { label: '宽度公差<br/>(mm)', name: 'WnegaToleranceWposiTolerance', width: 120, align: 'left', sortable: false },
                { label: '长度公差<br/>(mm)', name: 'HnegaToleranceHposiTolerance', width: 120, align: 'left', sortable: false },
                { label: '宽度公差x', name: 'WnegaTolerance', width: 120, align: 'left', hidden: true },
                { label: '宽度公差y', name: 'WposiTolerance', width: 120, align: 'left', sortable: false, hidden: true },
                { label: '长度公差x', name: 'HnegaTolerance', width: 120, align: 'left', hidden: true },
                { label: '长度公差y', name: 'HposiTolerance', width: 120, align: 'left', sortable: false, hidden: true },
                { label: '标准编号', name: 'StandardNumber_ALL', width: 120, align: 'left', sortable: false },
                { label: '特殊要求', name: 'MaterialDemand_ALL', width: 180, align: 'left', sortable: false },
                { label: '标准编号', name: 'StandardNumber', width: 120, align: 'left', hidden: true },
                { label: '特殊要求', name: 'MaterialDemand', width: 120, align: 'left', sortable: false, hidden: true },
                { label: '合件编号', name: 'CombineNO', width: 120, align: 'center', sortable: false },
                { label: '备注', name: 'FBZSM', width: 160, align: 'right', sortable: false },
                { label: '输入人员', name: 'InputUser', width: 70, align: 'left', sortable: false },
                { label: '输入日期', name: 'InputDate', width: 70, align: 'center', sortable: false },
                { label: '输入时间', name: 'InputTime', width: 70, align: 'center', sortable: false },
                ],
                pager: "#gridPager1",
                sortname: 'FProductionNO,InputDate,InputTime',
                sortorder:"asc",
                viewrecords: true,
                rownumWidth: 50,
                onSelectRow: function (rowId) {
                    var data = $("#gridList1").getRowData(rowId);

                    for (var idx in data) {
                        $("#{0}".format(idx)).val(data[idx]);
                    }

                    var initMaterialSizeData = function (data, ids) {
                        ids.forEach(function (id) {
                            $("#{0}".format(id)).val("C");
                        });

                        var vals = data.split("x");

                        for (var i = 0; i < vals.length; i++) {
                            $("#{0}".format(ids[i])).val(vals[i]);
                        }
                    }

                    var ids = "MaterialSizesAllT,MaterialSizesAllH,MaterialSizesAllW".split(",");

                    var jIds = "MaterialSizes_JH,MaterialSizes_JW".split(",");
                    //材料规格赋值，如果实际值不为空则赋实际值
                    !!data["MaterialSizes_SJBL"] && initMaterialSizeData(data["MaterialSizes_SJBL"], ids);
                    //如果实际值不为空则看工艺，如果工艺不为空则赋工艺
                    !data["MaterialSizes_SJBL"] && !!data["MaterialSizes"] && initMaterialSizeData(data["MaterialSizes"], ids);
                    
                    !!data["MaterialSizes_J"] && initMaterialSizeData(data["MaterialSizes_J"], jIds);

                    !!data["MaterialCode_SJBL"] && $("#MaterialCodeALL").val(data["MaterialCode_SJBL"]);
                    
                    !data["MaterialCode_SJBL"] && !!data["MaterialCode"] && $("#MaterialCodeALL").val(data["MaterialCode"]);
                },
                loadComplete: function (data) {
                    Index.dataList = data;
                }
            });
            $gridList1.jqGrid('setFrozenColumns');
            $gridList1.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        }
    };



</script>
<div class="layout" id="layout" style="height: 100%; width: 100%;">
    <h1>编辑剪切下料卡</h1>
    <header>
        <section class="container">
            <div class="row">
                <div class="col-md-2">
                    <label>零件编号</label>
                    <input id="FProductionNO" name="" placeholder="" type="text" class="form-control required"  readonly="readonly"/>
                </div>
                <div class="col-md-2">
                    <label>剪切图形</label>
                    <select id="ISImg" name="" class="form-control txt_FProCompanyName">
                        <option value="">==请选择==</option>
                         <option value="0">优选</option>
                         <option value="1">工艺</option>
                    </select>
                </div>
                <div class="col-md-3 butn_in_c">
                    <label>材料牌号</label>
                    <input id="MaterialCodeALL" name="" placeholder="" type="text" class="form-control required"  readonly="readonly"/>
                    <button id="butnQueryDetails" class="butn_query_in glyphicon glyphicon-search"></button>
                </div>
                <div class="col-md-2">
                    <label>毛坯类型</label>
                    <select id="RoughsType" name="" class="form-control txt_FProCompanyName">
                        <option value="">==请选择==</option>
                           <option value="K">K 块料</option>
                            <option value="T">T 条料</option>
                            <option value="L">L 落料</option>
                            <option value="Y">Y 异形</option>
                    </select>
                </div>
                <div class="col-md-3">
                    <label>毛坯尺寸</label>
                    <input id="RoughsSize" name="" placeholder="" type="text" class="form-control required" readonly="readonly"/>
                </div>
                <div class="col-md-3 short_input">
                    <label>材料规格</label>
                    <input id="MaterialSizesAllT" readonly="readonly" name="" value="" placeholder="厚度" type="text" class="form-control required disabled" />X
                    <input id="MaterialSizesAllH" name="" placeholder="宽度" type="text" class="form-control required" />X
                    <input id="MaterialSizesAllW" name="" placeholder="长度" type="text" class="form-control required" />
                </div>
                <div class="col-md-3 short_input">
                    <label>剪切规格</label>
                    <input id="MaterialSizes_JH" name="" placeholder="宽度" type="text" class="form-control required" />X
                    <input id="MaterialSizes_JW" name="" placeholder="长度" type="text" class="form-control required" />
                </div>
                <div class="col-md-1 line_input">
                    <label>一张板切</label>
                    <input id="FYZJK" name="" placeholder="" type="text" class="form-control required" /><label>块</label>
                </div>
                <div class="col-md-1 line_input">
                    <label>一块板切</label>
                    <input id="FYKJJ" name="" placeholder="" type="text" class="form-control required" /><label>个零件</label>
                </div>
                <div class="col-md-1 line_input">
                    <label>一张板切</label>
                    <input id="KZLJ" name="" placeholder="" type="text" class="form-control required" /><label>个零件</label>
                </div>
            </div>
        </section>
        <aside>
            <div class="btn-group">
                <a id="butnGoSortExample" class="btn btn-primary center-block"><span class="glyphicon glyphicon-search"></span>排样</a>
                <a id="butnGoArtPic" class="btn btn-primary center-block"><span class="glyphicon glyphicon-refresh"></span>工艺图</a>
                <a class="btn btn-primary center-block i1 i11"><span class="glyphicon glyphicon-refresh"></span>写入</a>
                <a id="butnBack" class="btn btn-primary center-block i1 i12"><span class="glyphicon glyphicon-print"></span>返回</a>
            </div>
        </aside>
    </header>
    <div class="condition">
        <section class="container">
            <div class="row">
                <div class="col-md-2">
                    <label>零件编号</label>
                    <input id="ProductionNo2" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="col-md-2">
                    <label>材料牌号</label>
                    <input id="MaterialCodeAll2" name="" placeholder="" type="text" class="form-control required" />
                </div>
                <div class="col-md-2">
                    <label>材料规格</label>
                    <input id="MaterialSizesAll2" name="" placeholder="请输入厚X宽X长" type="text" class="form-control required" />
                </div>
                <div class="col-md-2">
                    <label>下料类型</label>
                    <select id="IsBZGY2" name="" class="form-control txt_FProCompanyName">
                        <option value="">==请选择==</option>
                        <option value="B">B 标准</option>
                         <option value="D">D 代用</option>
                    </select>
                </div>
                <div class="col-md-2">
                    <label>剪切图形</label>
                    <select id="IsImg2" name="" class="form-control txt_FProCompanyName">
                        <option value="">==请选择==</option>
                         <option value="0">优选</option>
                         <option value="1">工艺</option>
                    </select>
                </div>
                <div class="col-md-2">
                    <label>毛坯类型</label>
                    <select id="RoughsType2" name="" class="form-control txt_FProCompanyName">
                            <option value="">==请选择==</option>
                           <option value="K">K 块料</option>
                            <option value="T">T 条料</option>
                            <option value="L">L 落料</option>
                            <option value="Y">Y 异形</option>
                    </select>
                </div>
            </div>
        </section>
        <aside>
            <div class="btn-group">
                <a id="btn_search1" class="btn btn-primary center-block"><span class="glyphicon glyphicon-search"></span>查询</a>
            </div>
        </aside>
    </div>
    <div class="table_c">
        <table id="gridList1" class="frozen_fixed"></table>
        <div id="gridPager1"></div>
    </div>
</div>
